
package com.medranocg.gd.alfresco

import com.medranocg.gd.alfresco.AlfrescoHttpClient
import com.medranocg.gd.alfresco.CASClient

import org.apache.commons.logging.LogFactory

import org.apache.http.impl.client.BasicCookieStore
import org.apache.http.impl.client.HttpClients

class AlfrescoHttpClientWithCASAndExplorer extends AlfrescoHttpClientWithExplorer  {
    
    private static final log = LogFactory.getLog(this)

    AlfrescoHttpClientWithCASAndExplorer(alfrescoConfig, user) {
        super(alfrescoConfig, user)
    }

    def getHttpClient() {

        def cookieStore = new BasicCookieStore()
        def casHttpClient = HttpClients.custom()
                                .setDefaultCookieStore(cookieStore).build()
        def casClient = new CASClient(alfrescoConfig)
        def cookie = casClient.login(casHttpClient, cookieStore)

        cookieStore.addCookie(cookie)
        def httpClient = HttpClients.custom()
                            .setDefaultCookieStore(cookieStore).build()
        httpClient
        
    }

}

